<?php

namespace app\api\model;

use think\Model;
use think\Request;
use think\Db;
use think\Session;

//
// +--------------------------------------+
// |PHP version 5.5
// +--------------------------------------+
// |后台管理权限模型
// +--------------------------------------+
// |2018/01/09
// +--------------------------------------+
// |罗彪
// +--------------------------------------+
// |知果汇
// +--------------------------------------+
class AdminRole extends Model
{
    public function role_add()
    {
        $data = Request::instance()->only(['name', 'desc', 'auth'], 'post');
        $data['time'] = time();
        if (isset($data['auth']) && is_array($data['auth'])) $data['auth'] = json_encode($data['auth']);
        $add = Db::name("role")->insert($data);
        if ($add) {
            return "success";
        } else {
            return "error";
        }
    }

    public function role_edit($id)
    {
        $data = Request::instance()->only(['name', 'desc', 'auth'], 'post');
        $data['time'] = time();
        if (isset($data['auth']) && is_array($data['auth'])) $data['auth'] = json_encode($data['auth']);
        $add = Db::name("role")->where('id', $id)->update($data);
        if ($add) {
            return "success";
        } else {
            return "error";
        }
    }

//    public function is_role()
//    {
//        $role = Session::get("role");
//        $where['controller'] = request()->controller();
//        $where['action'] = request()->action();
//        $id = Db::name("menu")->where($where)->value('id');
//        if (!in_array($id, $role)) {
//            throw new \think\exception\HttpException(404, '页面不存在');
//        }
//    }

}

?>